<template>
  <basePage :page-params="pageParams">
    <view
      v-for="(item, index) in recordsList"
      :key="index"
      class="list-bg"
      @click="qustionDetailFn(item)"
    >
      <view class="record-info-box">
        <view class="title">{{ item.questionnaireName }}</view>
      </view>
      <view class="time">{{ item.createTime }}</view>
    </view>
    <view class="u-p-b-40">
      <u-loadmore :status="status" />
    </view>
  </basePage>
</template>

<script>
import basePage from '@/components/base-page'
import { setPageParamsFn } from '@/common/common'
import {
  querynrEffectiveAuestionnaire
} from '@/api/yc_userInfo'
export default {
  name: 'GrowthValueRecords',
  components: {
    basePage
  },
  data() {
    return {
      pageParams: {
        // state: 'ERROR',
        emptyTitle: '信号可能跑到外星球了哦～',
        errorTitle: '请求失败',
        showButton: true
      },
      page: 1,
      pageSize: 20,
      totalPages: 0,
      recordsList: [], //   问卷列表数据
      status: 'loading',
    }
  },
  onLoad() {
    this.queryListFn()

  },
  onReachBottom() {
    if (this.pageParams.state == 'EMPTY') {
      this.page = 1
    } else {
      this.page++
    }
    if (this.page > this.totalPages) {
      this.status = ''
      return
    }
    this.queryListFn()
  },
  methods: {
    async queryListFn() {
      this.status = 'loading'
      const params = {
        pageNum: this.page,
        pageSize: this.pageSize,
      }
      const res = await querynrEffectiveAuestionnaire(params)
      this.status = ''
      if (res.code != 0) {
        this.$u.toast(res.msg)
        return
      }
      if (!res.data || (this.page == 1 && res.data.data.length == 0)) {
        setPageParamsFn(this, 'EMPTY', '矮油，这里空空如也~', false)
        return
      }
      if (this.page == 1) {
        this.recordsList = res.data.data
      } else {
        this.recordsList.push(...res.data.data)
      }
      this.totalPages = res.data.pageCount
      if (res.data.totalRecord <= this.pageSize) {
        this.status = 'nomore'
      }
    },
    qustionDetailFn:function(item){
      console.log('进入详情',item)
      uni.navigateTo({
        url: `/myAccount/questionSurvey/questionnaireSurvey?id=${item.id}&questionnaireName=${item.questionnaireName}`
      })
    }
  }
}
</script>

<style scoped lang="scss">
.list-bg{
  .record-info-box{
    text-indent: 24rpx;
    height: 64rpx;
    line-height: 64rpx;
    font-size: $uni-font-size-base;
    .title{
      width: calc(100% - 160rpx);
      float: left;
    }
  }
  .time{
    text-indent: 24rpx;
    height: 64rpx;
    line-height: 64rpx;
    color: $uni-text-color-tips;
    font-size: $uni-font-size-sm;
  }

}
</style>
